﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmExcecao.aspx.cs" Inherits="Sinacor.Tools.Web.ConstantesErro.frmExcecao" EnableEventValidation="false" ValidateRequest="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Cadastro de Exceções</title>
    <meta http-equiv="pragma" content="no-cache" />   
    <link href="Estilos.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function abrirMensagens()
        {
            //window.open('frmMensagem.aspx', 'Mensagens', 'status , scrollbars=1'); //comentado - esertorio - 200809241922
          myWindow = window.open('frmMensagem.aspx?idMensagem=' + document.getElementById('txtCodigoMensagemVinculada').value + '&FiltrarTipoMensagem=True', 'Mensagens', 'status , scrollbars=1 , width=1300, height=800'); //incluido paramentro [idMensagem] - esertorio - 200809241922
          myWindow.moveTo(70,0); 
          resetarForm();
        }        
        
        function showDelete(pObjTR)
        {
            //debugger;
            if (event.ctrlKey)
                pObjTR.childNodes[5].childNodes[0].style.display = 'block'
        }
        
        
        function setViewerItem(pObjTR, show)
        {
            /*
            Id
            Modulo
            SubModulo
            ResourceKey
            Descricao
            botão deletar
            código mensagem
            */
            
            
            document.getElementById('txtCodigo2').value = pObjTR.childNodes[0].innerText;
            document.getElementById('hdnCodigo2').value = pObjTR.childNodes[0].innerText;
            document.getElementById('txtModulo2').value = pObjTR.childNodes[1].innerText;
            document.getElementById('txtSubmodulo2').value = pObjTR.childNodes[2].innerText;
            
            if (pObjTR.childNodes[8].innerText != '')
            {
                document.getElementById('txtResourceKey2').value = pObjTR.childNodes[8].innerText.substring(pObjTR.childNodes[8].innerText.lastIndexOf('.')+1);
                document.getElementById('txtPrefixoResourceKey2').value = pObjTR.childNodes[8].innerText.substring(0, pObjTR.childNodes[8].innerText.lastIndexOf('.'));
            }
            
            //document.getElementById('txtMensagem2').value = pObjTR.childNodes[4].innerText;
            document.getElementById('txtMensagem2').value = pObjTR.childNodes[7].innerText;
            document.getElementById('txtCodigoMensagemVinculada2').value = pObjTR.childNodes[6].innerText;
            
            //debugger;
            var div = document.getElementById('divDetalhes');
            var iframe = document.getElementById('iframeDiv');
            //debugger;                       
            div.style.top = 0;
            div.style.left  = 0;
            iframe.style.top = div.style.top;
            iframe.style.left = div.style.left;
            
            div.style.display = (show ? 'block' : 'none');
            iframe.style.display = (show ? 'block' : 'none');
        }
        
       
        function setUpdateItem(pObjTR)
        {
            document.getElementById('hdnOperacao').value = 'a'; //determinar operação de alteração - npaulo/esertorio - 20080919
            document.getElementById('txtCodigo').value = pObjTR.childNodes[0].innerText;
            document.getElementById('hdnCodigo').value = pObjTR.childNodes[0].innerText;            
            document.getElementById('ddlModulo').value = pObjTR.childNodes[1].innerText;
            
            //document.getElementById('txtSubmodulo').value = pObjTR.childNodes[2].innerText; //exc - esertorio - 200810091930
            //document.getElementById('ddlSubModulo').value = pObjTR.childNodes[2].innerText; //inc - esertorio - 200810091930

            var objDdlSubModulo = document.getElementById('ddlSubModulo');
            var achou = false;
            for(var i = 0; i < objDdlSubModulo.options.length; i++)
            {
                if(objDdlSubModulo.options[i].text == pObjTR.childNodes[2].innerText)
                {
                    achou = true;
                    //alert('achou = true'); //debug
                    document.getElementById('ddlSubModulo').value = pObjTR.childNodes[2].innerText;
                    break;
                }
            }
            if(!achou)
            {
                //alert('achou = false'); //debug
                objDdlSubModulo.options[0] = new Option( pObjTR.childNodes[2].innerText, pObjTR.childNodes[2].innerText);
                objDdlSubModulo.options[0].selected = true;
            }

           
            if (pObjTR.childNodes[8].innerText != '')
            {
                document.getElementById('txtResourceKey').value = pObjTR.childNodes[8].innerText.substring(pObjTR.childNodes[8].innerText.lastIndexOf('.')+1);
                document.getElementById('txtPrefixoResourceKey').value = pObjTR.childNodes[8].innerText.substring(0, pObjTR.childNodes[8].innerText.lastIndexOf('.'));
            }
            
            //document.getElementById('txtMensagem').value = pObjTR.childNodes[4].innerText;
            document.getElementById('txtMensagem').value = pObjTR.childNodes[7].innerText;
            document.getElementById('txtCodigoMensagemVinculada').value = pObjTR.childNodes[6].innerText;
            document.getElementById('hdnCodigoMensagemVinculada').value = pObjTR.childNodes[6].innerText;
        }
        
        function resetarForm()
        {
            document.getElementById('hdnOperacao').value = 'i'; //determinar operação de inclusao - npaulo/esertorio - 200809262028
            document.getElementById('txtCodigo').value = '';
            document.getElementById('hdnCodigo').value = '';
            document.getElementById('ddlModulo').value = '';
            //document.getElementById('txtSubmodulo').value = ''; //exc - esertorio - 200810091930
            document.getElementById('ddlSubModulo').value = ''; //inc - esertorio - 200810091930
            document.getElementById('txtResourceKey').value = '';
            document.getElementById('txtPrefixoResourceKey').value = '';
            document.getElementById('txtMensagem').value = '';
            document.getElementById('txtCodigoMensagemVinculada').value = '';
            document.getElementById('hdnCodigoMensagemVinculada').value = '';
        }
        
        function validaCamposObrigatorios()
        {
            var msg = '';
           
            
            if (document.getElementById('ddlModulo').value.replace(/^\s+|\s+$/g, '') == '')
            {
                msg +=  'Selecione o modulo da exceção!\n';
            }
            
            //exc - esertorio - 200810091930
            //if (document.getElementById('txtSubmodulo').value.replace(/^\s+|\s+$/g, '') == '')
            //inc - esertorio - 200810091930
            if (document.getElementById('ddlSubModulo').value.replace(/^\s+|\s+$/g, '') == '')
            {
                msg +=  'Insira o submódulo da exceção!\n';
            }
            
            if (document.getElementById('txtMensagem').value.replace(/^\s+|\s+$/g, '') == '')
            {
                msg +=  'Insira a descrição da exceção!\n';            
            }
            
            if (msg != '')
            {
                alert(msg);
                return false;
            }
            
            return true;            
        }
    </script>
</head>
<body style="margin: 0 0 0 0; width: 100%; height: 100%;"> 
    <form id="frmExcecao" runat="server" style="margin: 0 0 0 0; width: 100%; height: 100%;">
        <table style="width: 100%;" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td style="width: 100%; " align="center">
                    <fieldset>
                        <legend><asp:Label ID="Label1" runat="server">Inclusão/Alteração de Exceção</asp:Label></legend>
                        <table style="width: 100%; " cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td style="width: 10%;" align="center">Código</td>
                                <!-- alterado ID="txtCodigo" propriedade Enabled de "false" para "true" - esertorio - 200809222036 -->
                                <!-- //incluido campo hdnOperacao - npaulo/esertorio - 20080919-->
                                <td style="width: 20%;" colspan="2" align="left">
                                	<asp:TextBox ID="txtCodigo" runat="server" Enabled="true" Width="90%"></asp:TextBox>
                                	<input type="hidden" id="hdnOperacao" runat="server" value="i" />
                                	<input id="hdnCodigo" type="hidden" runat="server" />
                                </td>
                                <td style="width: 40%;" align="right" colspan="2">
                                    <table style="width: 100%; " cellpadding="0" cellspacing="0" border="0">
                                        <tr align="right">
                                            <td style="width: 25%;">&nbsp;</td>
                                            <td style="width: 25%;">&nbsp;</td>
                                            <td style="width: 50%; text-align: right;" align="right">Mensagem vinculada</td>
                                        </tr>
                                    </table>                                       
                                </td>
                                <!-- alterado ID="txtCodigoMensagemVinculada" propriedade Enabled de "false" para "true" - esertorio - 200809222036 -->
                                <td style="width: 10%;" align="left">&nbsp;<asp:TextBox ID="txtCodigoMensagemVinculada" runat="server" Enabled="true" Width="90%"></asp:TextBox><input id="hdnCodigoMensagemVinculada" type="hidden" runat="server" /></td>
                                <td style="width: 20%;" align="center"><input type="button" id="btnVincular" onclick="abrirMensagens();" value="..." />  </td>
                            </tr>
                            <tr>
                                <td style="width: 10%;" align="center">Módulo</td>
                                <td style="width: 10%;" colspan="2">
                                    <asp:DropDownList ID="ddlModulo" runat="server" Width="100%" OnSelectedIndexChanged="ddlModulo_SelectedIndexChanged" AutoPostBack="true">
                                    </asp:DropDownList>
                                </td>
                                <td style="width: 10%;">Submódulo</td>
                                <td style="width: 30%;" align="left">
                                    <asp:DropDownList ID="ddlSubModulo" runat="server" Width="100%">
                                    </asp:DropDownList>
                                </td>
                                <td style="width: 10%;">&nbsp;</td>
                                <td style="width: 20%;" align="center">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="7" style="width: 20%;" >
                                    <table cellpadding="0" cellspacing="0" style="width: 100%;" border="0">
                                        <tr>
                                            <td style="width: 10%;">Resource Key</td>
                                            <td style="width: 20%;">
                                                <asp:TextBox ID="txtPrefixoResourceKey" runat="server" Width="90%" Enabled="false" ></asp:TextBox>
                                                <input type="hidden" runat="server" id="hdnResourKeyCompleta" />
                                            </td>
                                            <td style="width: 20%;">
                                                <asp:TextBox ID="txtResourceKey" runat="server" Width="90%" Enabled="false"></asp:TextBox>
                                            </td>
                                            <td style="width: 50%;">&nbsp;</td>
                                        </tr>
                                    </table>
                                
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
            <tr>
                <td style="width: 100%;" align="center">
                    <fieldset>
                        <legend>Descrição da Exceção</legend>
                        <table style="width: 100%;">
                            <tr align="center">
                                <td style="width: 33%;" >&nbsp;</td>
                                <td style="width: 34%;"><asp:TextBox MaxLength="255" TextMode="MultiLine"  Columns="50" Rows="6" ID="txtMensagem" runat="server"></asp:TextBox></td>
                                <td style="width: 33%;">&nbsp;</td>
                            </tr>
                        </table>
                    </fieldset>
                </td>               
            </tr>
            <tr>
                <td style="width: 100%;" align="center">
                    <table style="width: 100%;">
                        <tr align="center">
                            <td style="width: 85%;">&nbsp;</td>
                            <td style="width: 5%;" align="center"><asp:Button ID="btnPesquisar" runat="server" Text="Pesquisar" onclick="btnPesquisar_Click" /></td>
                            <td style="width: 5%;" align="center"><asp:Button ID="btnSalvar" runat="server" Text="Salvar" onclick="btnSalvar_Click" style="height: 26px" /></td>
                            <td style="width: 5%;" align="center"><input type="button" value="Novo" onclick="resetarForm();"/></td>
                        </tr>
                    </table>
                </td>               
            </tr>
            <tr >
                <td style="width: 100%;" align="center">
                    Para incluir uma mensagem clique em novo, para visualizar os detalhes dos itens pesquisados passe o mouse sobre os itens do grid, para alterar
                    selecione clique no item do grid. 
                </td>
            </tr>
            <tr>
                <td style="width: 100%;">
                    <fieldset>
                        <legend>Dados Cadastrados</legend>
                        <asp:GridView ID="grdTipoMensagem" runat="server" AutoGenerateColumns="False" 
                                Width="100%" AllowPaging="True" AllowSorting="True" 
                                onpageindexchanging="grdTipoMensagem_PageIndexChanging" 
                                onsorting="grdTipoMensagem_Sorting" 
                                onrowdatabound="grdTipoMensagem_RowDataBound" BorderColor="Black">
                                <PagerSettings Mode="Numeric" Position="Bottom" PageButtonCount="30"/>
                                <Columns>
                                    <asp:BoundField DataField="Id" HeaderText="Código" SortExpression="Id" >
                                        <HeaderStyle Width="10%" />
                                        <ItemStyle Width="10%" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Modulo" HeaderText="Módulo" SortExpression="Modulo" >
                                        <HeaderStyle Width="10%" />
                                        <ItemStyle Width="10%" />                                    
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Submodulo" HeaderText="Submódulo" SortExpression="Submodulo" >
                                        <HeaderStyle Width="10%" />
                                        <ItemStyle Width="10%" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="ResourceKey" HeaderText="Resource Key" SortExpression="ResourceKey" >
                                        <HeaderStyle Width="10%" />
                                        <ItemStyle Width="10%" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Descricao" HeaderText="Descricao" SortExpression="Descricao" >
                                        <HeaderStyle Width="20%" />
                                        <ItemStyle Width="20%" />
                                    </asp:BoundField>
                                    <asp:TemplateField HeaderText="Deletar">
                                        <ItemTemplate><asp:ImageButton runat="server" ID="Deletar" 
                                                ImageUrl="~/Imagens/delete.gif" onclick="Deletar_Click" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "Id")%>' />
                                        </ItemTemplate>
                                        <HeaderStyle Width="10%" />
                                        <ItemStyle Width="10%" />
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="CodigoMensagem" HeaderText="Código Mensagem" SortExpression="CodigoMensagem" >
                                        <HeaderStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                        <ItemStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Descricao" HeaderText="Descricao" SortExpression="Descricao" >
                                        <HeaderStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                        <ItemStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="ResourceKey" HeaderText="Resource Key" SortExpression="ResourceKey" >
                                        <HeaderStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                        <ItemStyle Width="10%" CssClass="COLUNA_ESCONDIDA" />
                                    </asp:BoundField>
                                </Columns>
                                <PagerStyle BackColor="#F0F0F0" />
                                <HeaderStyle BackColor="#F0F0F0" />
                        </asp:GridView>
                    </fieldset>
                </td>
            </tr>
            <tr>
                <td style="width: 100%; ">&nbsp;
                    <div id="divDetalhes" style="width: 100%; height: 200px; position: absolute; display: none; margin: 0 0 0 0; background-color: white; z-index: 99; " >
                        <table cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; margin: 0 0 0 0;">
                            <tr>
                                <td style="width: 100%; " align="center">
                                    <fieldset>
                                        <legend><asp:Label ID="Label2" runat="server">Dados da Exceção</asp:Label></legend>
                                        <table style="width: 100%; " cellpadding="0" cellspacing="0" border="0">
                                            <tr>
                                                <td style="width: 10%;" align="center">Código</td>
                                                <td style="width: 20%;" colspan="2"><asp:TextBox ID="txtCodigo2" runat="server" Enabled="false" Width="90%"></asp:TextBox><input id="hdnCodigo2" type="hidden" runat="server" /></td>
                                                <td style="width: 40%;" align="right" colspan="2">
                                                    <table style="width: 100%; " cellpadding="0" cellspacing="0" border="0">
                                                        <tr align="right">
                                                            <td style="width: 25%;">&nbsp;</td>
                                                            <td style="width: 25%;">&nbsp;</td>
                                                            <td style="width: 50%; text-align: right;" align="right">Mensagem vinculada</td>
                                                        </tr>
                                                    </table>                                       
                                                </td>
                                                <td style="width: 10%;">&nbsp;<asp:TextBox ID="txtCodigoMensagemVinculada2" runat="server" Enabled="false" Width="90%"></asp:TextBox><input id="hdnCodigoMensagemVinculada2" type="hidden" runat="server" /></td>
                                                <td style="width: 20%;" align="center">&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td style="width: 10%;" align="center">Módulo</td>
                                                <td style="width: 10%;" colspan="2"><asp:TextBox runat="server" ID="txtModulo2" Width="70%"></asp:TextBox></td>
                                                <td style="width: 10%;">Submódulo</td>
                                                <td style="width: 30%;" align="left">&nbsp;<asp:TextBox ID="txtSubmodulo2" runat="server" Width="50%"></asp:TextBox></td>
                                                <td style="width: 10%;"></td>
                                                <td style="width: 20%;" align="center">&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td colspan="7" style="width: 20%;" >
                                                    <table cellpadding="0" cellspacing="0" style="width: 100%;">
                                                        <tr>
                                                            <td style="width: 10%;">Resource Key</td>
                                                            <td style="width: 20%;">
                                                                <asp:TextBox ID="txtPrefixoResourceKey2" runat="server" Width="100%" Enabled="false" ></asp:TextBox>
                                                            </td>
                                                            <td style="width: 20%;">
                                                                <asp:TextBox ID="txtResourceKey2" runat="server" Width="100%" Enabled="false"></asp:TextBox>
                                                            </td>
                                                            <td style="width: 50%;">&nbsp;</td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </fieldset>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100%;" align="center">
                                    <fieldset>
                                        <legend>Descrição da Exceção</legend>
                                        <table style="width: 100%;">
                                            <tr align="center">
                                                <td style="width: 33%;" >&nbsp;</td>
                                                <td style="width: 34%;"><asp:TextBox MaxLength="255" TextMode="MultiLine"  Columns="50" Rows="6" ID="txtMensagem2" runat="server"></asp:TextBox></td>
                                                <td style="width: 33%;">&nbsp;</td>
                                            </tr>
                                        </table>
                                    </fieldset>
                                </td>               
                            </tr>
                        </table>
                    </div>
                    <iframe frameborder="0" scrolling="no" style="width: 100%; height: 200px; position: absolute; z-index: 90;" id="iframeDiv" />
                </td>
            </tr>        
        </table>
    </form>
</body>
</html>
